package com.fyzk.adapter;

import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.fyzk.activity.lottery.recommend_order.MyRecommendOrderBean;
import com.fyzk.utils.DateUtils;
import com.fyzk.utils.SpanUtils;
import com.fyzk.utils.TimeUtil;
import com.tyjc.lottery.R;

import java.math.BigDecimal;
import java.text.DecimalFormat;

public class OtherCenterAdapter extends BaseQuickAdapter<MyRecommendOrderBean, BaseViewHolder> {
    public OtherCenterAdapter() {
        super(R.layout.item_other_center);
    }

    @Override
    protected void convert(BaseViewHolder helper, MyRecommendOrderBean item) {
        boolean isBasketball = true;//是否篮球
        switch (item.getLotteryType()) {
            case 3001://竞彩篮球胜负
            case 3002://竞彩篮球让分胜负
            case 3003://竞彩篮球胜分差
            case 3004://竞彩篮球大小分
            case 3005://竞彩篮球混合过关
                isBasketball = true;
                break;
            case 3006://竞彩足球让球胜平负
            case 3007://竞彩足球比分
            case 3008://竞彩足球总进球数
            case 3009://竞彩足球半全场胜平负
            case 3010://竞彩足球胜平负
            case 3011://竞彩足球混合过关
                isBasketball = false;
                break;
        }
        Glide.with(mContext)
                .load(isBasketball ? R.drawable.icon_basketball : R.drawable.icon_football)
                .into((ImageView) helper.getView(R.id.iv_lottery_type));
        setInfo(helper.getView(R.id.tv_follow_total_amount), mContext.getString(R.string.follow_total_amount),
                new DecimalFormat("#0").format(item.getFollowTotalAmount() / 100));
        setInfo(helper.getView(R.id.tv_buy_self), mContext.getString(R.string.buy_self_amount),
                new DecimalFormat("#0").format(item.getAmount() / 100));
        setInfo(helper.getView(R.id.tv_brokerage), mContext.getString(R.string.brokerage),
                item.getProportions() + "%");
        setInfo(helper.getView(R.id.tv_follow_number), mContext.getString(R.string.follow_number),
                String.valueOf(item.getFollowTotalNumber()));

        //orderResultStatus（=4已中奖，=2未中奖，=5未开奖），way（=0就是不可再跟单，=2并且orderResultStatus=5就是可以跟单的）
        helper.setText(R.id.tv_lottery_type_name, isBasketball ?
                mContext.getString(R.string.jclq) :
                mContext.getString(R.string.jcz))
                .setText(R.id.tv_issue_time, String.format("%s 截止", item.getEndTime()))
                .setText(R.id.tv_win_money, String.format("%s米", new BigDecimal((double) item.getPrize() / 100).setScale(0, BigDecimal.ROUND_HALF_UP)))
                .setImageResource(R.id.iv_type, (item.getOrderResultStatus() == 3 || item.getOrderResultStatus() == 4) ?
                        R.drawable.icon_winning :
                        (item.getOrderResultStatus() == 2 ?
                                R.drawable.icon_losing_lottery :
                                R.drawable.icon_wait_lottery)
                )
                //orderResultStatus=5待开奖状态 当前时间小于截止时间可跟单
                .setGone(R.id.tv_follow, item.getOrderResultStatus() == 5
                        && System.currentTimeMillis() < TimeUtil.stringToLong(item.getEndTime()))
                .setGone(R.id.rl_type, !(item.getOrderResultStatus() == 5
                        && System.currentTimeMillis() < TimeUtil.stringToLong(item.getEndTime())))
                .setGone(R.id.tv_win_money, item.getOrderResultStatus() == 4)
                .addOnClickListener(R.id.tv_follow)
        ;
        helper.getView(R.id.tv_follow);

//        if (item.getOrderResultStatus() == 3 || item.getOrderResultStatus() == 4) {//中奖
//            helper.setText(R.id.tv_type, "红");
//            helper.setBackgroundRes(R.id.tv_type, R.drawable.shape_other_center_selecter_bg);
//        } else if (2 == item.getOrderResultStatus()) {//未中奖
//            helper.setText(R.id.tv_type, "黑");
//            helper.setBackgroundRes(R.id.tv_type, R.drawable.shape_other_center_selecter_black_bg);
//        } else {//可跟单
//            helper.setVisible(R.id.tv_type, false);
//        }
    }

    public void setInfo(TextView textView, String title, String content) {
        SpanUtils.with(textView)
                .appendLine(content)
                .setForegroundColor(mContext.getResources().getColor(R.color.black))
                .setFontSize(16, true)
                .append(title)
                .setForegroundColor(mContext.getResources().getColor(R.color.color_999999))
                .setFontSize(12, true)
                .create();
    }
}
